<!DOCTYPE html>
<html lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">

    <!--[if lt IE 9]>
        <style>body {display: none; background: none !important} </style>
        <meta http-equiv="Refresh" Content="0; url=//outdatedbrowser.com/" />
    <![endif]-->

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="author" content="Ren ZM">



<meta name="description" content="记录c++编译环境.Microsoft Visual Studio 2015.">
<meta name="keywords" content="c++">
<meta property="og:type" content="article">
<meta property="og:title" content="编译cpp-vs2015">
<meta property="og:url" content="https://littlepro.gitee.io/mytpages/2019/11/25/编译cpp-vs2015/index.html">
<meta property="og:site_name" content="Xbiubiubiu">
<meta property="og:description" content="记录c++编译环境.Microsoft Visual Studio 2015.">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2020-04-06T14:26:21.551Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="编译cpp-vs2015">
<meta name="twitter:description" content="记录c++编译环境.Microsoft Visual Studio 2015.">

<link rel="apple-touch-icon" href="/mytpages//apple-touch-icon.png">


    <link rel="alternate" href="/atom.xml" title="Xbiubiubiu" type="application/atom+xml">



    <link rel="shortcut icon" href="/mytpages//favicon.png">



    <link href="//cdn.bootcss.com/animate.css/3.5.1/animate.min.css" rel="stylesheet">



    <link href="//cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.min.css" rel="stylesheet">



    <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
    <link href="//cdn.bootcss.com/pace/1.0.2/themes/blue/pace-theme-minimal.css" rel="stylesheet">


<link rel="stylesheet" href="/mytpages/css/style.css">



<link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">


<title>编译cpp-vs2015 | Xbiubiubiu</title>

<script src="//cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>

<script>
    var yiliaConfig = {
        fancybox: true,
        animate: true,
        isHome: false,
        isPost: true,
        isArchive: false,
        isTag: false,
        isCategory: false,
        fancybox_js: "//cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.min.js",
        scrollreveal: "//cdn.bootcss.com/scrollReveal.js/3.1.4/scrollreveal.min.js",
        search: false
    }
</script>


    <script> yiliaConfig.jquery_ui = [false]; </script>



    <script> yiliaConfig.rootUrl = /mytpages/; </script>







    <script src="/mytpages/live2d-widget/autoload.js"></script>


</head></html>
<body>
  <div id="container">
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
    <header id="header" class="inner">
        <a href="/mytpages/" class="profilepic">
            <img src="/mytpages//img/avatar.png" class="animated zoomIn">
        </a>
        <hgroup>
          <h1 class="header-author"><a href="/mytpages/">Ren ZM</a></h1>
        </hgroup>

        
        <p class="header-subtitle">--ロリは正義</p>
        

        


        
            <div id="switch-btn" class="switch-btn">
                <div class="icon">
                    <div class="icon-ctn">
                        <div class="icon-wrap icon-house" data-idx="0">
                            <div class="birdhouse"></div>
                            <div class="birdhouse_holes"></div>
                        </div>
                        <div class="icon-wrap icon-ribbon hide" data-idx="1">
                            <div class="ribbon"></div>
                        </div>
                        
                        <div class="icon-wrap icon-link hide" data-idx="2">
                            <div class="loopback_l"></div>
                            <div class="loopback_r"></div>
                        </div>
                        
                        
                        <div class="icon-wrap icon-me hide" data-idx="3">
                            <div class="user"></div>
                            <div class="shoulder"></div>
                        </div>
                        
                    </div>
                    
                </div>
                <div class="tips-box hide">
                    <div class="tips-arrow"></div>
                    <ul class="tips-inner">
                        <li>菜单</li>
                        <li>标签</li>
                        
                        <li>友情链接</li>
                        
                        
                        <li>关于我</li>
                        
                    </ul>
                </div>
            </div>
        

        <div id="switch-area" class="switch-area">
            <div class="switch-wrap">
                <section class="switch-part switch-part1">
                    <nav class="header-menu">
                        <ul>
                        
                            <li><a href="/mytpages//mytpages/../">主页</a></li>
                        
                            <li><a href="/mytpages//mytpages/../archives/">所有文章</a></li>
                        
                            <li><a href="/mytpages//mytpages/../tags/">标签云</a></li>
                        
                            <li><a href="/mytpages//mytpages/../about/">关于我</a></li>
                        
                        </ul>
                    </nav>
                    <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fa Email" href="mailto:784709355@qq.com" title="Email"></a>
                            
                                <a class="fa GitHub" href="https://github.com/rzzz" title="GitHub"></a>
                            
                                <a class="fa Gitee" href="https://gitee.com/littlepro" title="Gitee"></a>
                            
                                <a class="fa V2EX" href="/mytpages/" title="V2EX"></a>
                            
                                <a class="fa 知乎" href="/mytpages/" title="知乎"></a>
                            
                                <a class="fa 网易云音乐" href="/mytpages/" title="网易云音乐"></a>
                            
                                <a class="fa bilibili" href="/mytpages/" title="bilibili"></a>
                            
                        </ul>
                    </nav>
                </section>
                
                
                <section class="switch-part switch-part2">
                    <div class="widget tagcloud" id="js-tagcloud">
                        <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/JavaScript/">JavaScript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/MySql/">MySql</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/NodeJS/">NodeJS</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/Nodejs/">Nodejs</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/PS3/">PS3</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/c/">c</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/c/">c++</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/cocos2dx/">cocos2dx</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/markdown/">markdown</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/note/">note</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/sort/">sort</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/test/">test</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/tool/">tool</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/usage/">usage</a></li></ul>
                    </div>
                </section>
                
                
                
                <section class="switch-part switch-part3">
                    <div id="js-friends">
                    
                      <a class="main-nav-link switch-friends-link" href="https://hexo.io">Hexo</a>
                    
                      <a class="main-nav-link switch-friends-link" href="https://pages.github.com/">GitHub</a>
                    
                      <a class="main-nav-link switch-friends-link" href="http://moxfive.xyz/">MOxFIVE</a>
                    
                    </div>
                </section>
                

                
                
                <section class="switch-part switch-part4">
                
                    <div id="js-aboutme">ロリは正義</div>
                </section>
                
            </div>
        </div>
    </header>                
</div>
    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
      <div class="overlay">
          <div class="slider-trigger"></div>
          <h1 class="header-author js-mobile-header hide"><a href="/" title="回到主页">Ren ZM</a></h1>
      </div>
    <div class="intrude-less">
        <header id="header" class="inner">
            <a href="/mytpages/" class="profilepic">
                <img src="/mytpages//img/avatar.png" class="animated zoomIn">
            </a>
            <hgroup>
              <h1 class="header-author"><a href="/mytpages/" title="回到主页">Ren ZM</a></h1>
            </hgroup>
            
            <p class="header-subtitle">--ロリは正義</p>
            
            <nav class="header-menu">
                <ul>
                
                    <li><a href="/mytpages/../">主页</a></li>
                
                    <li><a href="/mytpages/../archives/">所有文章</a></li>
                
                    <li><a href="/mytpages/../tags/">标签云</a></li>
                
                    <li><a href="/mytpages/../about/">关于我</a></li>
                
                <div class="clearfix"></div>
                </ul>
            </nav>
            <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fa Email" target="_blank" href="mailto:784709355@qq.com" title="Email"></a>
                            
                                <a class="fa GitHub" target="_blank" href="https://github.com/rzzz" title="GitHub"></a>
                            
                                <a class="fa Gitee" target="_blank" href="https://gitee.com/littlepro" title="Gitee"></a>
                            
                                <a class="fa V2EX" target="_blank" href="/mytpages/" title="V2EX"></a>
                            
                                <a class="fa 知乎" target="_blank" href="/mytpages/" title="知乎"></a>
                            
                                <a class="fa 网易云音乐" target="_blank" href="/mytpages/" title="网易云音乐"></a>
                            
                                <a class="fa bilibili" target="_blank" href="/mytpages/" title="bilibili"></a>
                            
                        </ul>
            </nav>
        </header>                
    </div>
    <link class="menu-list" tags="标签" friends="友情链接" about="关于我"/>
</nav>
      <div class="body-wrap"><article id="post-编译cpp-vs2015" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/mytpages/2019/11/25/编译cpp-vs2015/" class="article-date">
      <time datetime="2019-11-25T08:54:55.000Z" itemprop="datePublished">2019-11-25</time>
</a>


    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      编译cpp-vs2015
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        

        
    <div class="article-tag tagcloud">
        <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/mytpages/tags/c/">c++</a></li></ul>
    </div>

        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
          
        <p>记录c++编译环境.<br>Microsoft Visual Studio 2015.</p>
<a id="more"></a>

<h3 id="Microsoft-Visual-Studio-2015"><a href="#Microsoft-Visual-Studio-2015" class="headerlink" title="Microsoft Visual Studio 2015"></a>Microsoft Visual Studio 2015</h3><h4 id="熟悉工具-VC"><a href="#熟悉工具-VC" class="headerlink" title="熟悉工具(VC++)"></a>熟悉工具(VC++)</h4><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">vs2015（v140）</span><br><span class="line">vs预定义变量：</span><br><span class="line">  $(SolutionDir), $(ProjectDir), $(ProjectName), $(Configuration)</span><br><span class="line">常规：</span><br><span class="line">  目标平台，目标平台版本，输出目录，中间目录，目标文件名，目标文件扩展名，平台工具集</span><br><span class="line">  项目默认值：字符集(unicode-utf16)，MFC的使用(使用标准Windows库)</span><br><span class="line">调试：</span><br><span class="line">  命令，命令参数，工作目录</span><br><span class="line">VC++目录(可视化c++)</span><br><span class="line">  可执行文件目录</span><br><span class="line">  包含目录：$(VC_IncludePath);$(WindowsSDK_IncludePath);</span><br><span class="line">  库目录：$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86</span><br><span class="line">  Windows运行库目录：$(WindowsSDK_MetadataPath);</span><br><span class="line">C/C++:</span><br><span class="line">  常规：附加包含目录，调试信息格式(/ZI)，启动版权标志(/nologo)，警告等级(/W3)</span><br><span class="line">  优化：优化(/Od)</span><br><span class="line">  预处理器：预处理器定义，取消预处理器定义，保留注释</span><br><span class="line">  代码生成：启用字符串池，启动最小重新生成(/Gm)，启动C++异常(/EHsc)，运行库(/MDd)，结构成员对齐(/Zp4)，安全检查(/Gs)</span><br><span class="line">  语言：<span class="keyword">wchar_t</span>映射<span class="keyword">__wchat_t</span>，移除未引用的代码和数据</span><br><span class="line">  预编译头：预编译头(/Yc)，预编译头文件(stdafx.h)，预编译头输出文件($(IntDir)$(TargetName).pch)</span><br><span class="line">  输出文件：对象文件名，程序数据库文件名</span><br><span class="line">  浏览信息：启动浏览信息(否)</span><br><span class="line">  高级：调用约定(/Gd)</span><br><span class="line">  所有选项：罗列以上配置</span><br><span class="line">  命令行：/Yc<span class="string">"stdafx.h"</span> /GS ... /D <span class="string">"WIN32"</span> /D <span class="string">"_DEBUG"</span> /D <span class="string">"_WINDOWS"</span> /D <span class="string">"_UNICODE"</span> /D <span class="string">"UNICODE"</span> ...</span><br><span class="line">连接器：</span><br><span class="line">  常规：输出文件($(OutDir)$(TargetName)$(TargetExt))，附加库目录</span><br><span class="line">  输入：附加依赖项</span><br><span class="line">  命令行：/OUT:<span class="string">"D:\work_test\tttt\cpps2015\Win32Project1\Debug\Tdll.dll"</span> ...</span><br><span class="line">生成事件：</span><br><span class="line">  预先生成事件，预链接事件，后期生成事件</span><br></pre></td></tr></table></figure>

<h4 id="熟悉项目文件组织-VC"><a href="#熟悉项目文件组织-VC" class="headerlink" title="熟悉项目文件组织(VC++)"></a>熟悉项目文件组织(VC++)</h4><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line">.sln</span><br><span class="line">  # Visual Studio <span class="number">14</span></span><br><span class="line">  VisualStudioVersion = <span class="number">14.0</span><span class="number">.25420</span><span class="number">.1</span></span><br><span class="line">Project(<span class="string">"&#123;8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942&#125;"</span>) = <span class="string">"cctool"</span>, <span class="string">"cctool.vcxproj"</span>, <span class="string">"&#123;76A39BB2-9B84-4C65-98A5-654D86B86F2A&#125;"</span></span><br><span class="line">    ProjectSection(ProjectDependencies) = postProject</span><br><span class="line">        &#123;B7C2A162-DEC9<span class="number">-4418</span><span class="number">-972E-240</span>AB3CBFCAE&#125; = &#123;B7C2A162-DEC9<span class="number">-4418</span><span class="number">-972E-240</span>AB3CBFCAE&#125;</span><br><span class="line">        &#123;<span class="number">98</span>A51BA8-FC3A<span class="number">-415B</span>-AC8F<span class="number">-8</span>C7BD464E93E&#125; = &#123;<span class="number">98</span>A51BA8-FC3A<span class="number">-415B</span>-AC8F<span class="number">-8</span>C7BD464E93E&#125;</span><br><span class="line">    EndProjectSection</span><br><span class="line">EndProject</span><br><span class="line">Project(<span class="string">"&#123;8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942&#125;"</span>) = <span class="string">"libSpine"</span>, <span class="string">"..\..\spine\proj.win32\libSpine.vcxproj"</span>, <span class="string">"&#123;B7C2A162-DEC9-4418-972E-240AB3CBFCAE&#125;"</span></span><br><span class="line">EndProject</span><br><span class="line"></span><br><span class="line">.vcxproj</span><br><span class="line">  &lt;Project DefaultTargets=<span class="string">"Build"</span> ToolsVersion=<span class="string">"4.0"</span> xmlns=<span class="string">"http://schemas.microsoft.com/developer/msbuild/2003"</span>&gt;</span><br><span class="line">  &lt;ProjectName&gt;cctool&lt;/ProjectName&gt;</span><br><span class="line">ItemDefinitionGroup</span><br><span class="line">  ClCompile</span><br><span class="line">    &lt;AdditionalIncludeDirectories&gt;$(EngineRoot);..\Classes;%(AdditionalIncludeDirectories);$(_COCOS_HEADER_WIN32_BEGIN);$(_COCOS_HEADER_WIN32_END)&lt;/AdditionalIncludeDirectories&gt;</span><br><span class="line">    &lt;PreprocessorDefinitions&gt;WIN32;_DEBUG;_WINDOWS;COCOS2D_DEBUG=1;%(PreprocessorDefinitions)&lt;/PreprocessorDefinitions&gt;</span><br><span class="line">  Link</span><br><span class="line">    &lt;AdditionalDependencies&gt;%(AdditionalDependencies);$(_COCOS_LIB_WIN32_BEGIN);$(_COCOS_LIB_WIN32_END);libSpine.lib;android.lib&lt;/AdditionalDependencies&gt;</span><br><span class="line">    &lt;AdditionalLibraryDirectories&gt;$(OutDir);%(AdditionalLibraryDirectories);$(_COCOS_LIB_PATH_WIN32_BEGIN);$(_COCOS_LIB_PATH_WIN32_END)&lt;/AdditionalLibraryDirectories&gt;</span><br><span class="line">ItemGroup</span><br><span class="line">  &lt;ClCompile Include=<span class="string">"main.cpp"</span> /&gt;</span><br><span class="line">ItemGroup</span><br><span class="line">  &lt;ClInclude Include=<span class="string">"main.h"</span> /&gt;</span><br><span class="line">ItemGroup</span><br><span class="line">  &lt;ProjectReference Include=<span class="string">"..\..\cocos\2d\libcocos2d.vcxproj"</span>&gt;</span><br><span class="line"></span><br><span class="line">.vcxproj.filters</span><br><span class="line">  &lt;Project ToolsVersion=<span class="string">"4.0"</span> xmlns=<span class="string">"http://schemas.microsoft.com/developer/msbuild/2003"</span>&gt;</span><br><span class="line">  ItemGroup</span><br><span class="line">    &lt;Filter Include=<span class="string">"win32"</span>&gt;</span><br><span class="line">    &lt;Filter Include=<span class="string">"src"</span>&gt;</span><br><span class="line">    &lt;Filter Include=<span class="string">"src\nodes"</span>&gt;</span><br><span class="line">  ItemGroup</span><br><span class="line">    &lt;ClCompile Include=<span class="string">"main.cpp"</span>&gt;</span><br><span class="line">      &lt;Filter&gt;win32&lt;/Filter&gt;</span><br><span class="line">    &lt;/ClCompile&gt;</span><br><span class="line">  ItemGroup</span><br><span class="line">    &lt;ClInclude Include=<span class="string">"main.h"</span>&gt;</span><br><span class="line">      &lt;Filter&gt;win32&lt;/Filter&gt;</span><br><span class="line">    &lt;/ClInclude&gt;</span><br><span class="line"></span><br><span class="line">.vcxproj.user</span><br><span class="line">  &lt;Project ToolsVersion=<span class="string">"4.0"</span> xmlns=<span class="string">"http://schemas.microsoft.com/developer/msbuild/2003"</span>&gt;</span><br><span class="line">  PropertyGroup</span><br><span class="line">    &lt;LocalDebuggerWorkingDirectory&gt;..\Resources&lt;/LocalDebuggerWorkingDirectory&gt;</span><br></pre></td></tr></table></figure>

<h4 id="新建win32控制台项目"><a href="#新建win32控制台项目" class="headerlink" title="新建win32控制台项目"></a>新建win32控制台项目</h4><p>默认建立，编译运行。</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">int</span> argc, <span class="keyword">char</span>* argv[])</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="使用msvc命令行编译c"><a href="#使用msvc命令行编译c" class="headerlink" title="使用msvc命令行编译c++"></a>使用msvc命令行编译c++</h3><p>在Microsoft Visual Studio 14.0的\VC\bin目录里有cl和link工具，这里将工具拷贝到出来，并且没有配置Include和Lib环境变量。<br>Include-包含目录；Lib-库目录；附加包含目录；附加依赖项。<br>先对cpp进行编译，然后再进行链接，链接的时候，选择直接将lib和dll拷贝过来。至于lib和dll会再写一个记录。</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 基本cpp：test.cpp</span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// cl</span></span><br><span class="line">cl.exe test.cpp /c /EHsc /nologo /GS /W3 /Gy /O2 /WX- /Gd /MD /D <span class="string">"WIN32"</span> /D <span class="string">"NDEBUG"</span> /D <span class="string">"_WINDOWS"</span> /D <span class="string">"_UNICODE"</span> /D <span class="string">"UNICODE"</span></span><br><span class="line"><span class="comment">// link</span></span><br><span class="line">link.exe test.obj /out:test.exe /nologo /incremental:no</span><br></pre></td></tr></table></figure>

<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 使用c库和c++库：test1.cpp</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="built_in">std</span>::<span class="built_in">string</span> str = <span class="string">"hi"</span>;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">"%s\n"</span>, str.c_str());</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// cl</span></span><br><span class="line">cl.exe test1.cpp /c /EHsc /nologo /GS /W3 /Gy /O2 /WX- /Gd /MD /D <span class="string">"WIN32"</span> /D <span class="string">"NDEBUG"</span> /D <span class="string">"_WINDOWS"</span> /D <span class="string">"_UNICODE"</span> /D <span class="string">"UNICODE"</span></span><br><span class="line">/I<span class="string">"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include"</span> /I<span class="string">"C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt"</span></span><br><span class="line"><span class="comment">// lick</span></span><br><span class="line">link.exe test1.obj /out:test1.exe /nologo /incremental:no</span><br></pre></td></tr></table></figure>

<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 引用自定义头文件：stdafx.h,stdafx.cpp,testPCH.cpp</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"stdafx.h"</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="built_in">std</span>::<span class="built_in">string</span> str = <span class="string">"hi"</span>;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">"%s\n"</span>, str.c_str());</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// cl 不仅testPCH.cpp，还有stdafx.cpp</span></span><br><span class="line">cl.exe testPCH.cpp /c /EHsc /nologo /GS /W3 /Gy /O2 /WX- /Gd /MD /D <span class="string">"WIN32"</span> /D <span class="string">"NDEBUG"</span> /D <span class="string">"_WINDOWS"</span> /D <span class="string">"_UNICODE"</span> /D <span class="string">"UNICODE"</span></span><br><span class="line">/I<span class="string">"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include"</span> /I<span class="string">"C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt"</span></span><br><span class="line"><span class="comment">// link</span></span><br><span class="line">link.exe testPCH.obj stdafx.obj /out:testPCH.exe /nologo /incremental:no</span><br></pre></td></tr></table></figure>

<h3 id="阶段性总结"><a href="#阶段性总结" class="headerlink" title="阶段性总结"></a>阶段性总结</h3><p>宇宙第一IDE-Microsoft Visual Studio</p>
<h4 id="几个编译链接选项"><a href="#几个编译链接选项" class="headerlink" title="几个编译链接选项"></a>几个编译链接选项</h4><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">cl选项:</span><br><span class="line">/O1 最小化空间, /O2 最大化速度, /Od 禁用优化(默认值)</span><br><span class="line">/Gd __cdecl 调用约定, /Gz __stdcall 调用约定, /Gf 启用字符串池</span><br><span class="line">/Fe&lt;file&gt; 命名可执行文件, /Fo&lt;file&gt; 命名对象文件</span><br><span class="line">/Yc[file] 创建.PCH 文件, /Yu[file] 使用.PCH 文件, /Fp&lt;file&gt; 命名预编译头文件</span><br><span class="line">/D&lt;name&gt;&#123;=|#&#125;&lt;text&gt; 定义宏, /U&lt;name&gt; 移除预定义宏</span><br><span class="line">/I&lt;dir&gt; 添加到包含搜索路径</span><br><span class="line">/Zi 启用调试信息, /ZI 启用“编辑并继续”调试信息</span><br><span class="line">/c 只编译，不链接</span><br><span class="line">/nologo 取消显示版权消息</span><br><span class="line"></span><br><span class="line">link选项:</span><br><span class="line">/MT 与 LIBCMT.LIB 链接</span><br><span class="line">/MTd 与 LIBCMTD.LIB 调试库链接</span><br><span class="line">/MD 与 MSVCRT.LIB 链接</span><br><span class="line">/MDd 与 MSVCRTD.LIB 调试库链接</span><br><span class="line">运行时库:多线程(/MT)、多线程调试(/MTd)、多线程DLL(/MD)、多线程调试DLL(/MDd)。</span><br><span class="line">/MT和/MTd表示采用多线程CRT库的静态lib版本。</span><br><span class="line">  该选项会在编译时将运行时库以静态lib的形式完全嵌入。该选项生成的可执行文件运行时不需要运行时库dll的参加，</span><br><span class="line">  会获得轻微的性能提升，但最终生成的二进制代码因链入庞大的运行时库实现而变得非常臃肿。</span><br><span class="line">/MD和/MDd表示采用多线程CRT库的动态dll版本。</span><br><span class="line">  会使应用程序使用运行时库特定版本的多线程DLL。链接时将按照传统VC链接dll的方式将运行时库MSVCRxx.DLL的导入库MSVCRT.lib链接，</span><br><span class="line">  在运行时要求安装了相应版本的VC运行时库可再发行组件包（当然把这些运行时库dll放在应用程序目录下也是可以的）。</span><br></pre></td></tr></table></figure>


      
    </div>
    
  </div>
  
    


    <nav id="article-nav">
        
            <div id="article-nav-newer" class="article-nav-title">
                <a href="/mytpages/2019/11/26/cpp的lib和dll/">
                    cpp的lib和dll
                </a>
            </div>
        
        
            <div id="article-nav-older" class="article-nav-title">
                <a href="/mytpages/2019/11/23/编译cpp-准备/">
                    编译c++准备
                </a>
            </div>
        
    </nav>

  
</article>

    <div id="toc" class="toc-article">
        <strong class="toc-title">文章目录</strong>
        
            <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#Microsoft-Visual-Studio-2015"><span class="toc-number">1.</span> <span class="toc-text">Microsoft Visual Studio 2015</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#熟悉工具-VC"><span class="toc-number">1.1.</span> <span class="toc-text">熟悉工具(VC++)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#熟悉项目文件组织-VC"><span class="toc-number">1.2.</span> <span class="toc-text">熟悉项目文件组织(VC++)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#新建win32控制台项目"><span class="toc-number">1.3.</span> <span class="toc-text">新建win32控制台项目</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#使用msvc命令行编译c"><span class="toc-number">2.</span> <span class="toc-text">使用msvc命令行编译c++</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#阶段性总结"><span class="toc-number">3.</span> <span class="toc-text">阶段性总结</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#几个编译链接选项"><span class="toc-number">3.1.</span> <span class="toc-text">几个编译链接选项</span></a></li></ol></li></ol>
        
    </div>
    <style>
        .left-col .switch-btn,
        .left-col .switch-area {
            display: none;
        }
        .toc-level-3 i,
        .toc-level-3 ol {
            display: none !important;
        }
    </style>

    <input type="button" id="tocButton" value="隐藏目录"  title="点击按钮隐藏或者显示文章目录">

    <script>
        yiliaConfig.toc = ["隐藏目录", "显示目录", !!"false"];
    </script>



    
<div class="share">
    
        <div class="bdsharebuttonbox">
            <a href="#" class="fa fa-twitter bds_twi" data-cmd="twi" title="分享到推特"></a>
            <a href="#" class="fa fa-weibo bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
            <a href="#" class="fa fa-qq bds_sqq" data-cmd="sqq" title="分享给 QQ 好友"></a>
            <a href="#" class="fa fa-files-o bds_copy" data-cmd="copy" title="复制网址"></a>
            <a href="#" class="fa fa fa-envelope-o bds_mail" data-cmd="mail" title="通过邮件分享"></a>
            <a href="#" class="fa fa-weixin bds_weixin" data-cmd="weixin" title="生成文章二维码"></a>
            <a href="#" class="fa fa-share-alt bds_more" data-cmd="more"></i></a>
        </div>
        <script>
            window._bd_share_config={
                "common":{"bdSnsKey":{},"bdText":"编译cpp-vs2015　| Xbiubiubiu　","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
        </script>
    

    
</div>







    




    <div class="scroll" id="post-nav-button">
        
            <a href="/mytpages/2019/11/26/cpp的lib和dll/" title="上一篇: cpp的lib和dll">
                <i class="fa fa-angle-left"></i>
            </a>
        

        <a title="文章列表"><i class="fa fa-bars"></i><i class="fa fa-times"></i></a>

        
            <a href="/mytpages/2019/11/23/编译cpp-准备/" title="下一篇: 编译c++准备">
                <i class="fa fa-angle-right"></i>
            </a>
        
    </div>

    <ul class="post-list"><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/12/13/cpp：allocator-new/">cpp：allocator,new</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/28/CPP标准库-note/">CPP标准库-note</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/27/C与win32API/">C与win32API</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/27/C标准库-note/">C标准库</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/26/cpp的lib和dll/">cpp的lib和dll</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/25/编译cpp-vs2015/">编译cpp-vs2015</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/23/编译cpp-准备/">编译c++准备</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/18/simple-opengl/">simple opengl</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/15/cocos2dx-action/">cocos2dx-action</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/15/cocos2dx-schedule/">cocos2dx-schedule</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/14/cocos2dx在win32上写日志文件/">cocos2dx在win32上写日志文件</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/14/cocos2dx在win32上播放ogg/">cocos2dx在win32上播放ogg</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/14/cocos2dx字库缺失文字处理/">cocos2dx字库缺失文字处理</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/14/cocos2dx工作目录修改/">cocos2dx工作目录修改</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/13/cocos2dx-android/">cocos2dx-android</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/12/cocos2dx-win32/">cocos2dx-win32</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/11/Sublimer-Text/">Sublimer Text</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/07/潜意识？？设计模式/">潜意识？？设计模式</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/04/BST？AVL？红黑树？/">BST？AVL？红黑树？</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/01/几种排序算法示例代码/">几种排序算法示例代码</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/10/31/引子-基础算法？？/">引子-基础算法？？</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/10/31/引子-数据结构？？/">引子-数据结构？？</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/10/25/不会懂分布式系统的/">不会懂分布式系统的</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/10/24/MySql简单使用-adv/">MySql简单使用-adv</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/10/24/MySql简单使用/">MySql简单使用</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/10/18/PS3-HEN破相关记录/">PS3-HEN破相关记录</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/10/09/测试使用云函数扩展码云page/">测试使用云函数扩展码云page</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/10/09/web3-单页Web应用/">web3.单页Web应用</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/29/web2-简单网站的前后端分离/">web2.简单网站的前后端分离</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/29/web1-创建一个简单的网站/">web1.创建一个简单的网站</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/27/NodeJS-简单使用/">NodeJS 简单使用</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/27/JavaScript-other/">JavaScript-other</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/27/JavaScript-模块/">JavaScript-模块</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/27/JavaScript-简单使用/">JavaScript 简单使用</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/27/github-gitee-chrome文件树插件/">github & gitee chrome文件树插件</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/26/markdown-简单使用/">markdown 简单使用示例</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/25/hello-world/">Hello World</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/24/zzTest-article0/">zzTest article0</a></li></ul>




    <script>
        
    </script>
</div>
      <footer id="footer">
    <div class="outer">
        <div id="footer-info">
            <div class="footer-left">
                <i class="fa fa-copyright"></i> 
                2019-2020 Ren ZM
            </div>
            <div class="footer-right">
                <a href="http://hexo.io/" target="_blank" title="快速、简洁且高效的博客框架">Hexo</a>  Theme <a href="https://github.com/MOxFIVE/hexo-theme-yelee" target="_blank" title="简而不减 Hexo 双栏博客主题  v3.5">Yelee</a> by MOxFIVE <i class="fa fa-heart animated infinite pulse"></i>
            </div>
        </div>
        
            <div class="visit">
                
                    <span id="busuanzi_container_site_pv" style='display:none'>
                        <span id="site-visit" title="本站到访数"><i class="fa fa-user" aria-hidden="true"></i><span id="busuanzi_value_site_uv"></span>
                        </span>
                    </span>
                
                
                    <span>| </span>
                
                
                    <span id="busuanzi_container_page_pv" style='display:none'>
                        <span id="page-visit"  title="本页阅读量"><i class="fa fa-eye animated infinite pulse" aria-hidden="true"></i><span id="busuanzi_value_page_pv"></span>
                        </span>
                    </span>
                
            </div>
        
    </div>
</footer>
    </div>
    
<script data-main="/mytpages/js/main.js" src="//cdn.bootcss.com/require.js/2.2.0/require.min.js"></script>

    <script>
        $(document).ready(function() {
            var iPad = window.navigator.userAgent.indexOf('iPad');
            if (iPad > -1 || $(".left-col").css("display") === "none") {
                var bgColorList = ["#9db3f4", "#414141", "#e5a859", "#f5dfc6", "#c084a0", "#847e72", "#cd8390", "#996731"];
                var bgColor = Math.ceil(Math.random() * (bgColorList.length - 1));
                $("body").css({"background-color": bgColorList[bgColor], "background-size": "cover"});
            }
            else {
                var backgroundnum = 5;
                var backgroundimg = "url(/mytpages//background/bg-x.jpg)".replace(/x/gi, Math.ceil(Math.random() * backgroundnum));
                $("body").css({"background": backgroundimg, "background-attachment": "fixed", "background-size": "cover"});
            }
        })
    </script>





<div class="scroll" id="scroll">
    <a href="#" title="返回顶部"><i class="fa fa-arrow-up"></i></a>
    <a href="#comments" onclick="load$hide();" title="查看评论"><i class="fa fa-comments-o"></i></a>
    <a href="#footer" title="转到底部"><i class="fa fa-arrow-down"></i></a>
</div>
<script>
    // Open in New Window
    
        var oOpenInNew = {
            
            
            
            
            
            
             archives: ".archive-article-title", 
             miniArchives: "a.post-list-link", 
            
             friends: "#js-friends a", 
             socail: ".social a" 
        }
        for (var x in oOpenInNew) {
            $(oOpenInNew[x]).attr("target", "_blank");
        }
    
</script>

<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js">
</script>
  </div>
</body>
</html>